﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _42字符串练习
{
    class Program
    {
        static void Main(string[] args)
        {
            //练习一:接收用户输入的字符串，将其输入的字符反转
            //Console.WriteLine("请输入你要反转的字");
            //string str = Console.ReadLine();
            //char[] s1 = str.ToCharArray();
            //StringBuilder s2 = new StringBuilder();
            //for (int i = s1.Length - 1; i >= 0; i--)
            //{
            //    s2.Append(s1[i]);
            //}
            //str = s2.ToString();
            //Console.WriteLine(str);
            //Console.ReadKey();


            //练习二:"hello c sharp"->"sharp c hello"
            //string str = "hello c shaep";
            //string[] strNew = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            //for (int i = 0; i < strNew.Length / 2; i++)
            //{
            //    string temp = strNew[i];
            //    strNew[i] = strNew[strNew.Length - 1 - i];
            //    strNew[strNew.Length - 1 - i] = temp;
            //}
            //str = string.Join(" ", strNew);
            //Console.WriteLine(str);
            //Console.ReadKey();


            //练习三
            //string str = "abc@qq.com";
            //int index = str.IndexOf("@");
            //string s1 = str.Substring(0, index);
            //string s2 = str.Substring(index + 1);
            //Console.WriteLine(s1);
            //Console.WriteLine(s2);
            //Console.ReadKey();


            //练习四
            //string s = @"C:\Users\Administrator\Desktop\学习笔记\1.txt";
            //string[] str = File.ReadAllLines(s, Encoding.Default);
            //for (int i = 0; i < str.Length; i ++)
            //{
            //    string[] strNew = str[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            //    Console.WriteLine((strNew[0].Length > 10 ?strNew[0].Substring(0,8)+"...":strNew[0])+ "|" + strNew[1]);
            //}
            //Console.ReadKey();


            //练习五:让用户输入一句话，找出所有e的位置
            //string str = "sdfejekeejkeej";
            //int index = 0;
            //循环体：从上一次出现e的位置加1找下一次e出现的位置
            //循环条件：index != -1;
            //int counm = 0;
            //while (index != -1)
            //{
            //    counm++;
            //    index = str.IndexOf('e', index + 1);
            //    if(index == -1)
            //    {
            //        break;
            //    }
            //    Console.WriteLine("第{0}次出现e的位置是{1}", counm, index);
            //}
            //Console.ReadKey();


            //练习六
            //string str = "老牛他很邪恶";
            //if (str.Contains("邪恶"))
            //{
            //    str = str.Replace("邪恶","**");
            //}
            //Console.WriteLine(str);
            //Console.ReadKey();


            //练习七
            //string[] name = { "诸葛亮", "鸟叔", "卡卡西", "卡哇伊" };
            //string str = string.Join("|", name);
            //string[] strNew = str.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            //Console.WriteLine();
            //Console.ReadKey();
            

        }
    }
}
